import 'package:get/get.dart';
import 'package:logger/logger.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:study_demo/api/net.dart';
import 'package:study_demo/util/toast_utils.dart';

toast(String msg) {
  ToastUtils.show(msg, Get.overlayContext!);
}

class BaseController extends GetxController {
  Net api = Net.instance;

  Logger get logger {
    try {
      return Get.find<Logger>();
    } catch (e) {
      var logger = Logger();
      Get.put(logger);
      return logger;
    }
  }

  requestPermission(Permission permission, Function success,
      {Function? error}) async {
    permission.request().then((value) {
      if (value.isGranted)
        success.call();
      else {
        toast('请打开相关权限');
        error?.call();
      }
    });
  }
}
